home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-04-09 | 1.1 KB | 29 lines | [TEXT/KEEN] |
- # $ExpandAssertions : see "Debugging hAWK programs"
- # "Go to": see «Debugging hAWK programs» «b 1 Assertions»
- # (the tricky bits - treat quotes properly, and
- # avoid using sub(), since the replacement string might contain
- # a "&" which stands for "everything that was matched".)
- #
- # Pass it your problem program as the single input file:
- # overwrites the file, replacing a(assertion) with
- # assert(assertion, "assertion", line number) ###
- FNR == 1 {outfile = FILENAME}
- { if (match($0, /[ \t]*a\((.+)\)/))
- {
- match($0, /\((.+)\)/) #find the argument proper
- first = substr($0, RSTART+1, RLENGTH-2) #copy it
- second = first
- gsub(/"/, "\\\"", second) #escape quotes
- match($0, /[ \t]*/) #match starting white space
- starter = substr($0, RSTART, RLENGTH) #copy it
- $0 = starter "assert(" first ", \"" second "\", " FNR ") ###"
- ##sub(/a\((.+)\)/, "assert(" first ", \"" second "\", " FNR ") ###")
- ##-deleted, doesn't work properly if "second" contains a "&"
- }
- out[++i] = $0
- }
- END { close(outfile)
- for (j = 1; j <= i; ++j)
- print out[j] > outfile
- }
-